#include <unistd.h>
#include <stdio.h>
#include <termios.h>
#include <curses.h>
#include <term.h>
static FILE *output_stream = (FILE *)0;

char *menu[] = {
    "a - add new record",
    "d - delete record",
    "q - quit",
    NULL,
};

#define PASSWORD_LEN 8

void inputPasword(){
	struct termios initialrsettings,newrsettings;
	char password[ PASSWORD_LEN +1 ];
	tcgetattr(fileno(stdin),&initialrsettings);
	newrsettings = initialrsettings;
	newrsettings.c_lflag &= ~ECHO;
	printf("enter password:");
	
	if(tcsetattr(fileno(stdin), TCSAFLUSH, &newrsettings)!=0 ){
		fprintf(stderr,"could not set attributes\n");
	}else{
		fgets(password,PASSWORD_LEN,stdin);
		tcsetattr(fileno(stdin),TCSANOW,&initialrsettings);
		fprintf(stdout,"\n you entered %s\n",password);
	}
}

int char_to_terminal(int char_to_write)
{
    if (output_stream) putc(char_to_write, output_stream);
    return 0;
}

int main(int argc,char** argv){
	if(! isatty(fileno(stdout)) ){
		fprintf(stderr,"you need stty \n");
		return 1;
	}
	//int in=getchar();
	//printf("you input: %c\r\n",in);
	
	
	setupterm(NULL,fileno(stdout), (int *)0);
	char *cursor;
	const char *clear;
    char *esc_sequence;
    cursor = tigetstr("cup");
	clear = tigetstr("clear");
	
	tputs(clear, 1, (int *) char_to_terminal);
	
	tputs(tparm(cursor, 2, 2), 1, char_to_terminal);
	
    esc_sequence = tparm(cursor,5,30);
    putp(esc_sequence);
	
	sleep(1);
	return 0;
}
